package edu.je.history.Service;

import com.junqson.je.common.UserHolder;
import com.junqson.je.common.exception.BizException;
import com.junqson.je.common.model.ApiResult;
import com.junqson.je.common.model.User;
import edu.je.history.Mapper.HistoryInfoMapper;
import edu.je.history.Model.HistoryInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindException;

/**
 * @Description:
 * @author: Anhlaidh
 * @date: 2021-04-21 22:31
 */
@Service
public class CollectionService {
    @Autowired
    HistoryInfoMapper historyInfoMapper;
    public ApiResult putBrowseCollection(int companyId) {
        User user = UserHolder.get();
        HistoryInfo historyInfo = historyInfoMapper.getByIdAndCompany(user.getUserId(), companyId);
        if (historyInfo == null) {
            return ApiResult.error("no such data in datasource");
        }
        historyInfo.setIsmarked(true);
        historyInfoMapper.update(historyInfo);
        return ApiResult.success();
    }

    public ApiResult deleteBrowseCollection(int companyId) {
        User user = UserHolder.get();
        HistoryInfo historyInfo = historyInfoMapper.getByIdAndCompany(user.getUserId(), companyId);
        if (historyInfo == null) {
            return ApiResult.error("no such data in datasource");
        }
        historyInfo.setIsmarked(false);
        historyInfoMapper.update(historyInfo);
        return ApiResult.success();
    }
}
